const fs = require('fs');
fs.readFile('./07-Mojito.lrc', (err, data) => {
    if (err) {
        console.error(err);
    } else {
        let lrc = data.toString().split('\n');
        //因为lrc分为两部分，所以我们需要正则表达式提取这两部分，特别是对时间的提取。
        let regx = /\[(\d{2}):(\d{2})\.(\d{2})](.*)/;
        let newregx = /\[\w{2}:(.*)]/;
        //转换成数组,然后通过foreach遍历
        let start = new Date().getTime();
        lrc.forEach((value) => {
            //eval() 执行完要返回结果，而 exec() 执行完不返回结果
            let str = regx.exec(value);
            if (str) {
                let minute = parseFloat(str[1]);
                let second = parseFloat(str[2]);
                let millisecond = parseFloat(str[3]);
                let content = str[4];
                let end = new Date().getTime();
                let time = minute * 60 * 1000 + second * 1000 + millisecond - (end - start);
                setTimeout(() => {
                    console.log("[" + minute + ":" + second + ":" + millisecond + "]", content);
                }, time);
            } else {
                let deputy = newregx.exec(value);
                if (deputy) {
                    console.log(deputy[1]);
                }
            }
        });
    }
});